class UserController < ApplicationController

  def login
  end

  def choose
    if !session[:user_id]
      redirect_to(:action => :login)
    end
    @users = User.all
  end


  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])
    if @user.save
        session[:user_id] = @user.id
        redirect_to(:controller => :createquiz, :action => :index)
    else
        redirect_to(:action => :login)
      end
    end

  def validate
    if user = User.authenticate(params[:name], params[:password])
       session[:user_id] = user.id
       redirect_to :controller => :createquiz, :action => :index
  else
      flash[:alert] = "Invalid user id / password"
      redirect_to :action => :login, :name => params[:name]
  end
  end
end
